package com.lzq.springbootrabbitmq.Listen;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
public class Consumer {
    /*
    @RabbitListener(queues = "boot-queue")
    public void getMessage(Object meg){
        System.out.println("收到的消息" + meg);
    }
    */

    //手动ack,目的收到消息时，自动告诉exchange已收到，然后发生异常，消息还没消费，那么消息就不见了
    @RabbitListener(queues = "boot-queue")
    public void getMessage(String msg, Channel channel, Message message) throws IOException {
        System.out.println("收到的消息" + msg);
        //int i = 1/0;
        channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
    }

}
